/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import model.user.Director;
import model.user.Staff;

/**
 *
 * @author CUNEYT
 */
public class Campaign {

    private String title = null;
    private String status = null;
    private String type = null;
    private java.util.Date startDate;
    private java.util.Date endDate;
    private ArrayList<ConsultedCampaign> consulted;
    private Director director;
    private Client client;
    private Staff responsible;
    private ArrayList<Resource> resources;

    public Campaign(String title, String type, java.util.Date start, java.util.Date end, String stat, Director dir) {
        this.title = title;
        this.status = stat;
        this.type = type;
        this.startDate = start;
        this.endDate = end;
        this.director = dir;
        this.consulted = new ArrayList<ConsultedCampaign>();
        this.resources = new ArrayList<Resource>();
    }

    public Campaign(String title, String type, java.util.Date start, java.util.Date end, String stat) {
        this.title = title;
        this.status = stat;
        this.type = type;
        this.startDate = start;
        this.endDate = end;
        this.consulted = new ArrayList<ConsultedCampaign>();
        this.resources = new ArrayList<Resource>();
    }

    /*Campaign status*/
    public static final String ACTIVE = "active";
    public static final String NEGOTIATION = "negotiation";
    public static final String ARCHIVE = "archive";
    /*Campaign types*/
    public static final String INTERNET = "Internet";
    public static final String RADIO = "Radio";
    public static final String MAGAZINE_NEWSPAPER = "MAGAZINE/NEWSPAPER";
    public static final String TV = "TV";
    public static final String LEAFLET = "Leaflet";

    public ArrayList<Resource> getResources() {
        return resources;
    }

    public void setResources(ArrayList<Resource> resources) {
        this.resources = resources;
    }

    public void addResource(Resource r) {
        if (!resources.contains(r)) {
            resources.add(r);
        } else {
            int i = resources.indexOf(r);
            resources.get(i).add(r.getAmount());
        }
    }

    public Staff getResponsible() {
        return responsible;
    }

    public void setResponsible(Staff responsible) {
        this.responsible = responsible;
    }

    public Client getClient() {
        return client;
    }

    public void setClient(Client client) {
        this.client = client;
    }

    public ArrayList<ConsultedCampaign> getConsulted() {
        return consulted;
    }

    public void setConsulted(ArrayList<ConsultedCampaign> consulted) {
        this.consulted = consulted;
    }

    public void assignStaff(Staff s) {

        if (!getStaff().contains(s)) {
            ConsultedCampaign cc = new ConsultedCampaign(s, this);
            consulted.add(cc);
            s.addConsultedCampaign(cc);
        }
    }

    public Director getDirector() {
        return director;
    }

    public void setDirector(Director director) {
        this.director = director;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public void removeStaff(Staff s) {
        ConsultedCampaign cc = null;
        for (Iterator<ConsultedCampaign> it = consulted.iterator(); it.hasNext();) {
            cc = it.next();
            if (cc.getStaff().equals(s)) {
                s.removeConsultedCampaign(cc);
                consulted.remove(cc);
                break;
            }
        }
    }

    public ArrayList<Staff> getStaff() {

        ArrayList<Staff> staff = new ArrayList<Staff>();
        for (Iterator<ConsultedCampaign> it = consulted.iterator(); it.hasNext();) {
            ConsultedCampaign cc = it.next();
            staff.add(cc.getStaff());
        }
        return staff;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    @Override
    public String toString() {
        return getTitle();
    }
}
